<template>
	<view class="news-wrap">
		<view class="news-list">
			<template v-for="(item,index) in page_data">
				<view class="news-item" :key="index" @tap="jump('/pages/news/detail',{id:item.id})">
					<view class="news-item-image-box" v-if="item.thumbnail">
						<u-image :src="item.thumbnail" width="240rpx" height="160rpx"></u-image>
					</view>
					<view class="news-item-title-box">
						<view class="news-item-title">
							<text :style="{color:item.titlecolor}" :class="'fontType'+ item.fonttype">{{item.title}}</text>
						</view>
						<view class="news-item-time">
							<text>{{item.created_at}}</text>
						</view>
					</view>
				</view>
			</template>
		</view>
		<view class="loadmore-wrap">
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				current_page:1,
				last_page:1,
				page_size:10,
				status:'more',
				page_data:[]
			}
		},
		onShow() {
			// this.init_page_data();
		},
		onLoad() {
			this.init_page_data();
		},
		onReachBottom(){
			this.current_page ++;
			this.fetchNewsList();
		},
		methods:{
			init_page_data(){
				this.fetchNewsList();
			},
			fetchNewsList(){
				this.status = 'loading'
				let params = {
					page:this.current_page,
					per_page:this.page_size
				}
				this.$http('news.list',params).then(res=>{
					if(res.code == 1){
						this.status = res.data.data.length > 0 ? 'more': 'nomore'
						this.last_page ++;
						if(this.last_page > this.current_page){
							this.page_data = [...this.page_data,...res.data.data];
						}
					}
				})
			},
			jump(path,query){
				this.$Router.push({path,query});
			}
		}
	}
</script>

<style>
	page{
		background-color: #f1f1f1;
	}
</style>
<style lang="scss" scoped>
	.news-wrap{
		padding: 20rpx;
		.news-list{
			.news-item{
				background-color: #fff;
				display: flex;
				padding: 20rpx;
				margin-top: 20rpx;
				border-radius: 10rpx;
				align-items: center;
				.news-item-image-box{
					margin-right: 30rpx;
				
				}
				.news-item-title{
					margin-bottom: 20rpx;
				}
				.news-item-time{
					color: #999;
				}
			}
		}
	}
	.loadmore-wrap{
		padding: 40rpx;
	}
	.fontType1{
		font-weight: bold;
	}
	
	.fontType2{
		font-style: oblique;
	}
	
	.fontType3{
		font-weight: bold;
		font-style: oblique;
	}
	
	

</style>